/*
 * Copyright (c) 2018. 玺得（深圳）科技有限公司.保留所有权利. http://www.pi-top.com/ 玺得（深圳）科技有限公司保留所有代码著作权.如有任何疑问请访问官方网站与我们联系. 代码只针对特定需求定制编码，不得在未经允许或授权的情况下对外传播扩散.恶意传播者，法律后果自行承担. 本代码仅用于pps-cloud系统.
 */
package com.pitop.sample.service;

import com.pitop.core.entity.Page;
import com.pitop.core.exceptions.BaseException;
import com.pitop.core.exceptions.SampleException;
import com.pitop.sample.api.SampleFeignApi;
import com.pitop.sample.entity.Sample;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * 样品
 *
 * @author pi-top
 */
@Service("sampleSVImpl")
@Slf4j
public class SampleSVImpl {

    @Autowired
    private SampleFeignApi sampleFeignApi;

    /**
     * 加载一个对象Sample
     *
     * @param id id* @param code 样品编码
     * @return Sample
     */
    public Sample load(java.lang.Long id, java.lang.String code) {
        if (id == null && code == null) {
            throw new SampleException(BaseException.BaseExceptionEnum.Illegal_Param);
        }
        return sampleFeignApi.load(id, code);
    }

    /**
     * 加载一个对象Sample 通过id
     *
     * @param id id
     * @return Sample
     */
    public Sample loadById(java.lang.Long id) {
        if (id == null) {
            throw new SampleException(BaseException.BaseExceptionEnum.Illegal_Param);
        }
        return sampleFeignApi.loadById(id);
    }

    /**
     * 加载一个对象Sample 通过code
     *
     * @param code 样品编码
     * @return Sample
     */
    public Sample loadByCode(java.lang.String code) {
        if (code == null) {
            throw new SampleException(BaseException.BaseExceptionEnum.Illegal_Param);
        }
        return sampleFeignApi.loadByCode(code);
    }


    /**
     * 删除对象Sample
     *
     * @param id id* @param code 样品编码
     * @return Sample
     */

    public void delete(java.lang.Long id, java.lang.String code) {
        if (id == null && code == null) {
            throw new SampleException(BaseException.BaseExceptionEnum.Illegal_Param);
        }
        sampleFeignApi.delete(id, code);
    }


    /**
     * 查询Sample分页
     *
     * @param sample   对象
     * @param curPage  当前页
     * @param pageSize 分页条数
     * @return List<Sample>
     */
    public List<Sample> list(Sample sample, int curPage, int pageSize) {
        return sampleFeignApi.list(sample, curPage, pageSize);
    }

    /**
     * 查询Sample分页
     *
     * @param id       id* @param code  样品编码
     * @param curPage  当前页
     * @param pageSize 分页条数
     * @return List<Sample>
     */
    public List<Sample> list(java.lang.Long id, java.lang.String code, int curPage, int pageSize) {
        if (curPage < 0) {
            curPage = 1;
        }

        if (pageSize < 0) {
            pageSize = Page.limit;
        }

        Sample sample = new Sample();
        sample.setId(id);
        sample.setCode(code);

        return sampleFeignApi.list(sample, curPage, pageSize);
    }


    public int count(java.lang.Long id, java.lang.String code) {
        return sampleFeignApi.count(id, code);
    }


    public int count(Sample sample) {
        return sampleFeignApi.count(sample);
    }


    /**
     * 保存
     *
     * @param sample 实体
     * @throws BaseException
     */
    public void save(Sample sample) {
        if (sample == null) {
            throw new SampleException(BaseException.BaseExceptionEnum.Illegal_Param);
        }
        sampleFeignApi.build(sample);
    }

    /**
     * 更新
     *
     * @param sample 实体
     * @throws BaseException
     */
    public void modify(Sample sample) {
        if (sample == null) {
            throw new SampleException(BaseException.BaseExceptionEnum.Illegal_Param);
        }
        sampleFeignApi.modify(sample);
    }

}
